@mixin unstyled-button () {
  // Styles for <button>s should @include this to remove the browser's default styling.
  border: none;
  font-size: inherit;
  font-family: inherit;
  font-weight: inherit;
  text-decoration: inherit;
  color: inherit;
  line-height: inherit;
  background-color: transparent;
  text-align: inherit;
  padding: 0;
  cursor: pointer;
}

%google-icon {
  background-image: url("");
}

%github-icon {
  background-image: url("");
}

@mixin overflow-ellipsis () {
  // For when you want a block of text to fit within a box on a single line and
  // use ellipsis if it would overflow the box.
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

%pseudo-img-tag {
  // Use this, and background-image: url();, when you want to
  // create a DIV that feels like an IMG tag.
  //
  // Generally, we do this to allow Internet Explorer to show
  // user-created SVG images (e.g., app icons) rescaled to
  // the size of the (pseudo) IMG tag.
  //
  // Prefer contain to cover here, because downscaling an image is
  // more likely to produce good results for user-provided images
  // (e.g. whitelabel logo or app icons) than clipping the image will.
  background-size: contain;
  background-repeat: no-repeat;
}

%button-base {
  // Default button shape, layout, and size.
  cursor: pointer;
  border-radius: 5px;
  padding: 4px 8px;
  min-height: 26px;
  font-size: 13px;
  font-family: inherit;
  text-align: center;
  text-decoration: none;
}

%button-disabled {
  cursor: auto;
  color: #777777;
  background-color: #efefef;
  border: 1px solid lighten(#afafaf, 10%);
  &:hover {
    color: #777777;
    background-color: #efefef;
    border: 1px solid lighten(#afafaf, 10%);
  }
}

%button-link {
  background: none;
  border: none;
  color: black;
  text-decoration: underline;
}

%button-primary {
  // A button coloring for the primary action of a form.
  background-color: $darker-purple-color;
  color: white;
  border: 1px solid darken($darker-purple-color, 10%);
  &:hover {
    background-color: #714daa;
  }
  &:disabled {
    @extend %button-disabled;
  }
}

%button-secondary {
  // A button coloring for secondary (less important) actions.
  background-color: white;
  color: black;
  border: 1px solid darken(white, 30%);
  &:hover {
    background-color: darken(white, 10%);
  }
  &:disabled {
    @extend %button-disabled;
  }
}

%button-danger {
  color: #900;
  background-color: white;
  border: 1px solid darken(white, 30%);
  &:hover {
    background-color: #af1010;
    color: white;
  }
  &:disabled {
    @extend %button-disabled;
  }
}

%button-dark {
  background-color: #303030;
  color: #ffffff;
  border: 1px solid #4e4e4e;
  transition: background-color .35s;
  &:hover {
    background-color: #4e4e4e;
  }
}

%standard-form {
  // Styles that we tend to reuse in forms, particularly in the admin panel.
  .form-group {
    margin-bottom: 10px;
  }

  .checkbox-group {
    // We want to make it so that labels for checkboxes and other associated content align neatly.
    // To accomplish this, we remove the checkbox from the flow, place all other content inside a
    // box with some left padding, and then pull the checkbox back out to the side with negative margin.
    // We might want to do something similar for radio buttons some day.
    position: relative;
    padding-left: 24px;
    margin-bottom: 10px;
    input[type=checkbox] {
      position: absolute;
      margin-left: -24px;
      font-size: 16px;
    }
  }

  label {
    display: block;
    font-weight: normal;
    font-size: 20px;
  }

  input[type=text], input[type=password], input[type=number], input[type=email], select {
    min-height: 30px;
  }

  input[type=text], input[type=password], input[type=number], input[type=email], select, textarea {
    display: block;
    width: 100%;
    color: #222;
    background-color: white;
    padding: 4px;
    font-size: 16px;
    font-family: inherit;
    border-radius: 2px;
    border: 1px solid #d3d3d3;
    &:disabled {
      color: #666;
      background-color: #efefef;
    }
    &:invalid {
      border: 1px solid #c00;
    }
  }

  .form-subtext {
    font-size: 14px;
    color: #666;
  }

  .button-row {
    width: 100%;
    display: flex;
    flex-direction: row-reverse;
    align-items: stretch;
    justify-content: flex-start;
    >*:not(:first-child) {
      margin-right: 10px;
    }
  }

  button[type="submit"] {
    @extend %button-base;
    @extend %button-primary;
  }

  button[type=button] {
    @extend %button-base;
    @extend %button-secondary;
    &.danger {
      @extend %button-danger;
    }
  }

  a.button {
    @extend %button-base;
    @extend %button-secondary;
    &.primary {
      @extend %button-primary;
    }
    &.danger {
      @extend %button-danger;
    }
    font-weight: inherit;
  }

  &.disabled {
    // Used for marking that the entire form is disabled.  Note that this does not disable the
    // <input>s; you should still add the disabled attribute to each control.
    color: #666 !important; // Grey out all text uniformly.
  }
}

%search-row {
  // A search bar that grows to the size of its container.
  >label {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-start;

    >span.search-icon {
      @extend %pseudo-img-tag;
      background-image: url("/search.svg");
      background-size: 24px 24px;
      background-position: center;
      display: inline-block;
      width: 32px;
      height: 32px;
      vertical-align: top;
    }
    >input.search-bar {
      flex: 1 1 auto;
      font-size: 16pt;
      height: 32px;
      padding-left: 4px;
      background-color: $grainlist-searchbar-background-color;
      border: 1px solid $grainlist-searchbar-outline-color;
      &:focus {
        border: 1px solid $grainlist-searchbar-outline-color-focus;
      }
    }
  }
}
